package com.chinamoney.wppm.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chinamoney.wppm.entity.EleForm;
import com.chinamoney.wppm.service.EleFormService;
import com.chinamoney.wppm.service.UserService;
import com.chinamoney.wppm.util.ResultMessage;

/**
 * 
 * @author Jason_Jiang
 *
 */
@RestController
public class EleFormController {
	
	@Autowired
	private UserService userService;
	
	

	@Autowired
	private EleFormService eleFormService;

	
	/**
	 * 获取预算花费明细
	 * @param budgetFrom
	 * @param statelabels
	 * @return
	 */
	@GetMapping("eform/list/bdm/{budgetFrom}")
	public ResultMessage<?> getEformsByBdm(@PathVariable("budgetFrom") String budgetFrom, String statelabels) {
		return eleFormService.getEformsByBdm(budgetFrom, statelabels);
	}
	
	/**
	 * 获取预算花费情况（根据电子需求单的工作量评估进行计算）
	 * @param budgetFrom
	 * @param statelabels
	 * @return
	 */
	@GetMapping("eform/cost/{budgetFrom}")
	public ResultMessage<?> getBdmCostByStatelabel(@PathVariable("budgetFrom") String budgetFrom, String statelabels) {
		return eleFormService.getBdmCostByStatelabel(budgetFrom, statelabels);
	}
	
	
	/**
	 * 获取电子需求单列表
	 * @param code
	 * @param businessName
	 * @param stateNow
	 * @param limit
	 * @param offset
	 * @return
	 */
	@GetMapping("eform/list")
	public Map<String, Object> getEleForms(
			@RequestParam(value = "code", required = false, defaultValue = "") String code,
			@RequestParam(value = "businessName", required = false, defaultValue = "") String businessName,
			@RequestParam(value = "stateNow", required = false, defaultValue = "") String stateNow, Integer limit,
			Integer offset) {
		return eleFormService.getEleForms(code, businessName, stateNow, offset, limit);
	}

	/**
	 * 根据预算获取对应的需求单
	 * 
	 * @param id 预算管理的ID
	 * @return
	 */
	@GetMapping("eform/bdm/{id}")
	public Map<String, Object> getFormsByBdm(@PathVariable("id") String id, Integer limit, Integer offset) {
		return eleFormService.getFormsByBdm(id, offset, limit);
	}

	/**
	 * 电子需求单使用情况
	 * @param rows
	 * @return
	 */
	@GetMapping("eform/echart")
	public Map<String, Object> createCharts(int rows) {
		return eleFormService.createCharts(rows);
	}
	
	/**
	 * 根据ID获取需求单详细信息
	 * @return
	 */
	@GetMapping("eform/{id}")
	public ResultMessage<EleForm> getEformById(@PathVariable("id") String id) {
		EleForm eForm = eleFormService.getEformById(id);
		eForm.setDemandEstimator(userService.getUserByIds(eForm.getDemandEstimator()));
		eForm.setDesignEstimator(userService.getUserByIds(eForm.getDesignEstimator()));
		eForm.setDevelopEstimator(userService.getUserByIds(eForm.getDevelopEstimator()));
		eForm.setOperationEstimator(userService.getUserByIds(eForm.getOperationEstimator()));
		eForm.setProposer(userService.getUserByIds(eForm.getProposer()));
		return ResultMessage.createSuccessResultMessage(eForm);
	}

}
